import request from '@/utils/request'

const api = {
    repoList: '/supply/repoList',
    typeList: '/supply/typeList',
    stuffList: '/supply/list',
    stuffUpdate: '/supply/update'
}

export default api

const Map = {
    'descend': 'desc',
    'ascend': 'asc'
}

export function getRepoList () {
    return request({
        url: api.repoList,
        method: 'get'
    })
}

export function getTypeList (parameter) {
    return request({
        url: api.typeList,
        method: 'get',
        params: {
            location: parameter.location
        }
    })
}

export function getStuffList (parameter) {
    return request({
        url: api.stuffList,
        method: 'get',
        params: {
            location: parameter.location || '一号仓库',
            type: parameter.type || '鞋类',
            name: parameter.name,
            order: Map[parameter.order] || 'desc',
            page: parameter.page || 1,
            pageSize: parameter.pageSize || 10
        }
    })
}

export function updateStuff (parameter) {
    return request({
        url: api.stuffUpdate,
        method: 'put',
        params: {
            id: parameter.id,
            img: parameter.img,
            price: parameter.price,
            name: parameter.name,
            type: parameter.type
        }
    })
}
